package ypmits.simpledraw {
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Rectangle;

	/**
	 * @author Dave Lenz
	 */
	public class Cross extends Sprite {

		private var size : int;
		private var linethickness : Number;
		private var color : uint;
		private var align : String;
		private var square : Sprite;
		private var fillsquare : Boolean;
		private var fillsquarealpha : Number;

		
		/**
		 * This draws a Plus-sign from it's center (or from any other part of the StageAlign.*)
		 */
		public function Cross( size : int = 13, linethickness : Number = 4, color : uint = 0xFF9900, align : String = "CENTER", fillSquare : Boolean = true, fillSquareAlpha : Number = 0 ) {
			this.size = size;
			this.linethickness = linethickness;
			this.color = color;
			this.align = align;
			this.fillsquare = fillSquare;
			this.fillsquarealpha = fillSquareAlpha;
			
			var holder : Shape = new Shape( );
			addChild( holder );
			
			holder.graphics.clear( );
			holder.graphics.beginFill( color );
			holder.graphics.drawRect( (size * .5) - (linethickness * .5), 0, linethickness, size );
			holder.graphics.endFill( );
			holder.graphics.beginFill( color );
			holder.graphics.drawRect( 0, (size * .5 ) - (linethickness * .5), size, linethickness );
			holder.graphics.endFill( );
			holder.width = size;
			holder.height = size;
			
			SimpleDrawAUtil.align( holder, align );
			
			if( fillsquare ) addFillSquare( fillsquarealpha );
		}

		
		private function addFillSquare( transparency : Number ) : void {
			var r : Rectangle = this.getRect( this );
			square = new Sprite( );
			square.graphics.beginFill( 0xFF9900, transparency );
			square.graphics.drawRect( r.x, r.y, r.width, r.height );
			addChildAt( square, 0 );
		}

		
		public function removeFillSquare() : void {
			if( square ) {
				removeChild( square );
				square = null;
			}
		}
	}
}
